/// specified as well as the exe suffix
fn filename_parts(target: Option<&str>)
-> CargoResult<(Option<(String, String)>, String)> {
- let mut process = try!(util::process("rustc"));
+ let mut process = try!(util::process(util::rustc()));
process.arg("-")
.arg("--crate-name").arg("_")
.arg("--crate-type").arg("dylib")
use std::path::Path;
use std::process::Output;
-use util::{CargoResult, ProcessError, ProcessBuilder, process};
+use util::{self, CargoResult, ProcessError, ProcessBuilder, process};
/// Trait for objects that can execute commands.
pub trait ExecEngine: Send + Sync {
pub fn new(ty: CommandType) -> CargoResult<CommandPrototype> {
Ok(CommandPrototype {
builder: try!(match ty {
- CommandType::Rustc => process("rustc"),
- CommandType::Rustdoc => process("rustdoc"),
+ CommandType::Rustc => process(util::rustc()),
+ CommandType::Rustdoc => process(util::rustdoc()),
CommandType::Target(ref s) |
CommandType::Host(ref s) => process(s),
}),
/// The second element of the tuple returned is the target triple that rustc
/// is a host for.
pub fn rustc_version() -> CargoResult<(String, String)> {
- let output = try!(try!(util::process("rustc"))
+ let output = try!(try!(util::process(util::rustc()))
.arg("-vV")
.exec_with_output());
let output = try!(String::from_utf8(output.stdout).map_err(|_| {
return cargo_home.or(user_home);
}
+pub fn rustc() -> String {
+ env::var("RUSTC").unwrap_or_else(|_| "rustc".to_string())
+}
+
+pub fn rustdoc() -> String {
+ env::var("RUSTDOC").unwrap_or_else(|_| "rustdoc".to_string())
+}
+
fn walk_tree<F>(pwd: &Path, mut walk: F) -> CargoResult<()>
where F: FnMut(File, &Path) -> CargoResult<()>
{
-pub use self::config::Config;
+pub use self::config::{Config, rustc, rustdoc};
pub use self::process_builder::{process, ProcessBuilder};
pub use self::errors::{CargoResult, CargoError, ChainError, CliResult};
pub use self::errors::{CliError, ProcessError};
jobs = 1 # number of jobs to run by default (default to # cpus)
```
-# Configuration of registry cache
+# Environment Variables
-Cargo maintains a local cache of the registry index and of git
-checkouts of crates. By default these are stored under
-`$HOME/.cargo`. The location can be overridden by setting the
-`CARGO_HOME` environment variable.
+Cargo recognizes a few global environment variables to configure how it runs:
+
+* `CARGO_HOME` - Cargo maintains a local cache of the registry index and of git
+ checkouts of crates. By default these are stored under `$HOME/.cargo`, but
+ this variable overrides the location of this directory.
+* `RUSTC` - Instead of running `rustc`, Cargo will execute this specified
+ compiler instead.
+* `RUSTDOC` - Instead of running `rustdoc`, Cargo will execute this specified
+ `rustdoc` instance instead.
execs().with_status(101));
});
+test!(rustc_env_var {
+ let p = project("foo")
+ .file("Cargo.toml", r#"
+ [package]
+ name = "foo"
+ version = "0.0.1"
+ authors = []
+ "#)
+ .file("src/lib.rs", "");
+ p.build();
+
+ assert_that(p.cargo("build")
+ .env("RUSTC", "rustc-that-does-not-exist").arg("-v"),
+ execs().with_status(101)
+ .with_stderr("\
+Could not execute process `rustc-that-does-not-exist -vV` ([..])
+
+Caused by:
+[..]
+"));
+ assert_that(&p.bin("a"), is_not(existing_file()));
+});
+
test!(filtering {
let p = project("foo")
.file("Cargo.toml", r#"